from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP

# 公钥
with open("pub_key.pem", "rb") as file:
  pub_key_text = file.read()
  pub_key = RSA.import_key(pub_key_text)
  # 加密
  with open("certificate.json", "rb") as file:
    text = file.read()
    cipher = PKCS1_OAEP.new(pub_key)
    etext = cipher.encrypt(text)
    with open("../result/encrypt.certificate", "wb") as encryptFile:
      encryptFile.write(etext)
#
# 解密
# cipher_de = PKCS1_v1_5.new(pri_key)
# dtext = cipher_de.decrypt(etext, None)
# print("解密：", dtext)
